﻿#region License

// Another free, open solution by someone who gets it.
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#endregion

using System;
using System.Collections.Generic;

using Patterns.Fluency;

namespace Patterns.Reflection
{
	///<summary>
	///	Provides an interface for components that act as reflective wrappers for object instances.
	///</summary>
	public interface IReflection<out T> : IFluentInterface where T : class
	{
		///<summary>
		///	Gets the reflected object.
		///</summary>
		T Target{ get; }

		/// <summary>
		/// 	Gets the value.
		/// </summary>
		/// <param name = "name">The field or property name.</param>
		/// <param name = "valueHandler">The value handler.</param>
		/// <param name = "indexArguments">The index arguments if applicable.</param>
		/// <returns>The current reflection.</returns>
		IReflection<T> GetValue(MemberName name, Action<object> valueHandler, IEnumerable<object> indexArguments = null);

		/// <summary>
		/// 	Sets the value.
		/// </summary>
		/// <param name = "name">The field or property name.</param>
		/// <param name = "value">The value.</param>
		/// <param name = "indexArguments">The index arguments if applicable.</param>
		/// <returns>The current reflection.</returns>
		IReflection<T> SetValue(MemberName name, object value, IEnumerable<object> indexArguments = null);

		/// <summary>
		/// 	Runs the method with the specified name.
		/// </summary>
		/// <param name = "name">The method name.</param>
		/// <param name = "arguments">The arguments, if any..</param>
		/// <param name = "returnValueHandler">The return value handler, if any.</param>
		/// <returns>The current reflection.</returns>
		IReflection<T> Run(MemberName name, IEnumerable<object> arguments = null, Action<object> returnValueHandler = null);
	}

	///<summary>
	///	Provides a non-generic variety of the <see cref = "IReflection{T}" /> contract.
	///</summary>
	public interface IReflection : IReflection<object>
	{
		///<summary>
		///	Sets the reflection target.
		///</summary>
		///<param name = "instance">The target instance.</param>
		IReflection SetTarget(object instance);
	}
}